package com.itedge.solutionmanager.domain.impl;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.springframework.security.core.GrantedAuthority;

import com.itedge.infrastructure.domain.IEntity;


@Entity
@Table(name="EMPLOYEE_AUTHORITY")
public class EmployeeAuthority implements IEntity, GrantedAuthority {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;	

	@Version
    @Column(name = "version")
    private Integer version;
	
	@Column(name ="AUTHORITY")
	@Size(max = 255)
	private String authority;
	
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name="EMPLOYEES_AUTHORITIES",
            joinColumns=@JoinColumn(name="AUTHORITY_ID"),
            inverseJoinColumns=@JoinColumn(name="EMPLOYEE_ID")
        )
    private Set<Employee> employess = new HashSet<Employee>(); 

	@Override
	public String getAuthority() {
		return this.authority;
	}

	public Set<Employee> getEmployess() {
		return employess;
	}

	public void setEmployess(Set<Employee> employess) {
		this.employess = employess;
	}

	@Override
	public Integer getVersion() {
		return version;
	}
	
	@Override
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}
